package com.vision.app;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.web.WebApplicationInitializer;

import javax.annotation.Resource;
import java.io.File;

@SpringBootApplication
@ServletComponentScan
@ComponentScan(value = "com.vision")
public class PMLApplication extends SpringBootServletInitializer implements WebApplicationInitializer,CommandLineRunner {


    @Resource
    private Environment env;

    public static void main(String[] args) {
        SpringApplication.run(PMLApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
        System.out.println("项目启动");
        // 获取配置文件路径
        String path = env.getProperty("vision.mxgraphFilePath");
        System.out.println("参数路径："+ path);
        if(StringUtils.isNotBlank(path))
        {
            // 判断是否存在该文件夹路径，没有则创建
            createDir(path);
        }
        else
        {
            throw new Exception("检查application.yml中的vision.mxgraphFilePath参数");
        }


    }

    public static boolean createDir(String path) throws Exception {
        boolean result = false;

        try
        {
            File dir = new File(path);
            if (!dir.exists())
            {
                dir.mkdirs();
                result = true;
            }
            else
            {
                result = true;
            }
            return result;
        } catch (Exception var3)
        {
            throw new Exception(var3);
        }
    }
}
